# encoding: utf-8
import sys   
reload(sys)
sys.setdefaultencoding('utf-8')
from traceback import print_tb
import matplotlib.pyplot as plt;
import numpy as np;
import pandas as pd

data=pd.read_table("/home/student/桌面/HW2/C.txt",sep=',',header=None)
m=0
j=0
x=[[0]*20 for i in range(4)]
f=[[0]*20 for i in range(4)]
for i in range(len(data[0])):
    if(j==5*(m+1)):
        m=m+1
        j=0
    x[m][j]=data[0][i]
    f[m][j]=data[1][i]
    j=j+1
xx=np.arange(-1,1,0.0001)
y = 1/(25*xx*xx+1)
plt.figure()
for i in range(1,5):
    p=f[0][0]
    for j in range(1,5*i):
        s=1
        for l in range(j):
            s=s*(xx-x[i-1][l])
        p=p+f[i-1][j]*s
    plt.plot(xx,p)
plt.plot(xx,y,'--')
plt.title("the Runge phenomenon of exerciseC")
plt.savefig("C.png")